package spring_cloud.demo.api_gateway;

import javax.servlet.http.HttpServletRequest;

import org.springframework.http.HttpStatus;
import com.netflix.zuul.ZuulFilter;
import com.netflix.zuul.context.RequestContext;

public class AccessFilter extends ZuulFilter{

	@Override
	public Object run() {
		RequestContext ctx = RequestContext.getCurrentContext();
        HttpServletRequest request = ctx.getRequest();
        if (request.getParameter("plus") != null) {
			ctx.setSendZuulResponse(false);
			ctx.setResponseStatusCode(HttpStatus.OK.value());
			ctx.setResponseBody("Welcome, following skins are on sale.");
			return null;
		}
		return null;
	}

	@Override
	public boolean shouldFilter() {
		// TODO Auto-generated method stub
		return true;
	}

	@Override
	public int filterOrder() {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public String filterType() {
		// TODO Auto-generated method stub
		return "pre";
	}

}
